package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author yb0os1
 * @since 2024-12-04
 */
@Api(tags = "我的课程相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    private final ILearningLessonService learningLessonService;
    @ApiOperation("分页查询我的课表")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessonPage(PageQuery page){
        return learningLessonService.queryMyLessonPage(page);
    }

    @ApiOperation("查询正在学习的课程")
    @GetMapping("/now")
    public LearningLessonVO queryMyCurrentLesson(){
        return learningLessonService.queryMyCurrentLesson();
    }

    @ApiOperation("检查课程是否有效")
    @GetMapping("/{courseId}/valid")
    Long isLessonValid(@PathVariable Long courseId){
        return learningLessonService.checkIsValidLesson(courseId);
    }
    @ApiOperation("查询用户课表中指定课程状态")
    @GetMapping("/{courseId}")
    public LearningLessonVO queryLessonStatus(@PathVariable Long courseId){
        return learningLessonService.queryLessonStatus(courseId);
    }

    @ApiOperation("创建学习计划")
    @PostMapping("/plans")
    public void createLearningPlan(@RequestBody @Validated LearningPlanDTO dto){
        learningLessonService.createLearningPlan(dto);
    }
    /**
     * 统计课程学习人数
     * @param courseId 课程id
     * @return 学习人数
     */
    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程学习人数")
    public Integer countLearningLessonByCourse(@PathVariable Long courseId){
        return learningLessonService.countLearningLessonByCourse(courseId);
    }

    /**
     * 删除失效的课程
     * @param courseId
     */
    @ApiOperation("删除失效的课程")
    @DeleteMapping("/{courseId}/count")
    public void deleteLesson(@PathVariable Long courseId){
        learningLessonService.deleteLesson(courseId);
    }

    @ApiOperation("查看学习计划进度")
    @GetMapping("/plans")
    public LearningPlanPageVO queryLearningPlan(@Validated PageQuery page){
        return learningLessonService.queryLearningPlan(page);
    }
}
